package com.kczd.jinlan.view.mine;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.kczd.jinlan.R;
import com.kczd.jinlan.adapter.TabLayoutAdapter;
import com.kczd.jinlan.view.mine.fragment.ExpenditureFragment;
import com.kczd.jinlan.view.mine.fragment.IncomeFragment;
import com.kczd.jinlan.utils.OrderUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * yang_g
 * 零钱明细
 * Created by Administrator on 2017/5/19.
 */

public class SmallActivity extends AppCompatActivity {
    private TabLayout tab_layout;
    private ViewPager pager_view;
    private TextView id_fanhui;

    private List<Fragment> list;
    private String[] titles = {"余额支出", "余额收入"};
    private TabLayoutAdapter adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.small_activity);
        initView();
    }

    private void initView() {
        //实例化
        pager_view = (ViewPager) findViewById(R.id.pager_view);
        tab_layout = (TabLayout) findViewById(R.id.tab_layout);
        id_fanhui = (TextView) findViewById(R.id.id_fanhui);
        id_fanhui.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        /**
         * 设置tablayout的长度
         */
        tab_layout.post(new Runnable() {
            @Override
            public void run() {
                OrderUtils.setIndicator(tab_layout, 15, 15);
            }
        });

        //页面，数据源
        list = new ArrayList<>();
        list.add(new ExpenditureFragment());
        list.add(new IncomeFragment());

        //ViewPager的适配器
        adapter = new TabLayoutAdapter(getSupportFragmentManager(), list, titles);
        pager_view.setAdapter(adapter);
        //绑定
        tab_layout.setupWithViewPager(pager_view);

    }
}
